
function layer_confirm(url, msg) {
    var newUrl = "";
    if (url.match("[\?]")) {
        newUrl = url + "&inajax=1";
    } else {
        newUrl = url + "?inajax=1";
    }
    if (msg == null) {
        msg == '确认要执行吗？';
    }
    layer.confirm(msg, function (index) {
        window.location.href = newUrl;
    });
}
//删除一条记录
function layer_del(url) {
    var newUrl = "";
    if (url.match("[\?]")) {
        newUrl = url + "&inajax=1";
    } else {
        newUrl = url + "?inajax=1";
    }
    layer.confirm('确认要删除吗？', function (index) {
        window.location.href = newUrl;
    });
}

//删除多条记录
function layer_dels(name) {
    if ($("input[name='" + name + "[]']:checked").length < 1) {
        layer.alert('请勾选信息！');
        return false;
    }
    layer.confirm('确认要删除吗？', function (index) {
        document.getElementById('cpform').submit();
    });
}

//打开页面
function layer_open(title, url, w, h) {
    if (title == null || title == '') {
        title = false;
    }
    if (url == null || url == '') {
        url = "404.html";
    }
    if (w == null || w == '') {
        w = 800;
    }
    if (h == null || h == '') {
        h = ($(window).height() - 50);
    }
    var newUrl = "";
    if (url.match("[\?]")) {
        newUrl = url + "&inajax=1";
    } else {
        newUrl = url + "?inajax=1";
    }
    layer.open({
        type: 2,
        area: [w + 'px', h + 'px'],
        fix: false,
        maxmin: true,
        shade: 0.4,
        title: title,
        content: newUrl
    });
}


//大窗口打开页面
function layer_open_full(title, url) {
    var newUrl = "";
    if (url.match("[\?]")) {
        newUrl = url + "&inajax=1";
    } else {
        newUrl = url + "?inajax=1";
    }
    var index = layer.open({
        type: 2,
        title: title,
        content: newUrl
    });
    layer.full(index);
}


//关闭弹出层
function layer_close() {
    var index = parent.layer.getFrameIndex(window.name);
    parent.layer.close(index);
}


//上传附件
function layer_upload_att(url) {
    layer.open({
        type: 2,
        title: '上传附件',
        area: ['500px', '430px'],
        content: url
    });
}


//图像裁剪
function layer_img_cropper(cid, url) {
    var str = $('#' + cid).val();
    if (str == '') {
        layer.msg('请先上传图片！');
        return false;
    }
    if (url.indexOf('?') != -1) {
        url = url + '&f=' + window.btoa(unescape(encodeURIComponent(str))) + '&cid=' + cid;
    } else {
        url = url + '?f=' + window.btoa(unescape(encodeURIComponent(str))) + '&cid=' + cid;
    }
    layer.open({
        type: 2,
        title: '图像裁剪',
        area: ['750px', '510px'],
        content: url
    });
}


//图片预览
function layer_img_preview(id, src) {
    if (src == '')
        return;
    layer.tips('<img src="' + htmlspecialchars(src) + '" height="100">', '#' + id, {
        tips: [1, '#fff']
    });
}

//删除多文件上传
function remove_li(obj) {
    $(obj).parent().remove();
}

//html实体转换
function htmlspecialchars(str) {
    str = str.replace(/&/g, '&amp;');
    str = str.replace(/</g, '&lt;');
    str = str.replace(/>/g, '&gt;');
    str = str.replace(/"/g, '&quot;');
    str = str.replace(/'/g, '&#039;');
    return str;
}

